<template>
	<view class="hui">
		<view class="head">
			<u-navbar :autoBack="true" :safeAreaInsetTop="true" :placeholder="true" bgColor="transparent">
				<view class="u-nav-slot b_flex_c" slot="center">
					<view class="city">待分货列表</view>
				</view>
			</u-navbar>
		</view>
		<view class="top_box" :style="'top:'+(top)+'px'">
			<view class="search_box">
				<view class="search">
					<u-search @search="getList" v-model="params.name" bgColor='#F5F5F5' placeholder="搜索商品名称"
						:show-action="false"></u-search>
				</view>
				<u-icon name="calendar" size="30" color="#353535" @click="dateShow=true"> </u-icon>
			</view>

			<view class="tab">
				<u-tabs :scrollable='false' :list="tabList" @click="click" lineColor="#4092F0" lineWidth="40"
					:activeStyle="{color:'#4092F0',fontWeight:'bold'}" :inactiveStyle="{color: '#454553'}"
					itemStyle='height:80rpx;'></u-tabs>
			</view>

		</view>

		<view style="height:84px;"></view>

		<view class="list_box">

			<view class="list_info" @click="to(item)" v-for="(item,index) in list" :key="index">
				<view class="flex">
					<image class="l_img" :src="item.goods_img"></image>
					<view>
						<view class="name">{{item.goods_name}}</view>
						<view class="flex sku">
							<view>毛重约{{item.mz}}斤</view>
							<view class="xian"></view>
							<view>净重约{{item.jz}}斤</view>
						</view>
					</view>
					<view class="status">{{item.statusText}}</view>
				</view>
				<view class="num_box">
					<view class="flexc mt">
						<view> 下单(件):</view>
						<view class="num">{{item.buy_num}}</view>
					</view>
					<view class="flexc mt">
						<view> 订单已退(件):</view>
						<view class="num">{{item.r_num}}</view>
					</view>
					<view class="flexc mt">
						<view> 应收(件):</view>
						<view class="num">{{item.y_num}}</view>
					</view>
					<view class="flexc mt">
						<view> 已分(件):</view>
						<view class="num">{{item.fj_num}}</view>
					</view>
					<view class="flexc mt">
						<view> 未分(件):</view>
						<view class="num">{{item.w_num}}</view>
					</view>
				</view>
			</view>

		</view>

		<view style="height:84px;"></view>

		<view class="bot_box">
			<view class="btn" @click="make()">扫码分货</view>
		</view>

		<view v-if="show" class="bitmap">
			<image src="/static/img/no_content.png" mode="widthFix"></image>
			<view>暂时没有订单哦~</view>
		</view>

		<u-calendar v-if="time" @confirm="change" :closeOnClickOverlay="true" @close="dateShow=false"
			:monthNum="time.monthNum" :minDate="time.minDate" :maxDate="time.maxDate" :show="dateShow"
			mode="single"></u-calendar>

	</view>
</template>

<script>
	import {
		TimeShow,
		fhList
	} from "@/require/api.js";
	export default {
		data() {
			return {
				activeTab: 0,
				tabList: [{
						name: '全部',
						val: ''
					},
					{
						name: '待分货',
						val: 1
					},
					{
						name: '分货中',
						val: 2
					},
					{
						name: '已完成',
						val: 3
					}
				],
				list: [],
				total: 0,
				params: {
					page: 1,
					status: 0,
					token: '',
					name: '',
					time: ''
				},
				show: false,
				dateShow: false,
				time: '',
				top: 0

			}
		},
		onShow() {
			this.top = uni.getSystemInfoSync().statusBarHeight + 44;
		},
		onLoad() {
			this.getTimeShow();
			this.getList();
		},
		methods: {
			async getTimeShow() {
				let {
					code,
					data
				} = await TimeShow();
				if (code == 1) {
					this.time = data;
				}
			},
			change(e) {
				this.params.time = e[0];
				this.getList();
				this.dateShow=false;
			},
			to(e) {
				uni.navigateTo({
					url: '/pages/fh/info?ids=' + e.ids
				})
			},
			make() {
				let _ = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {

						console.log(res);

						let data = res.result.split('?id=');

						let params = {
							ids: data[data.length - 1]
						};
						_.to(params);

					}
				})
			},
			click(e) {
				this.params.status = e.val;
				this.getList();
			},
			setShow() {
				if (this.total < 1) {
					this.show = true;
				} else {
					this.show = false;
				}
			},
			async getList() {
				this.params.page = 1;
				let {
					code,
					data
				} = await fhList(this.params);
				if (code == 1) {
					this.list = data.data;
					this.total = data.total;
					this.setShow();
				}
			}
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.params.page++;
				fhList(this.params).then(res => {
					res.data.data.forEach((res) => {
						this.list.push(res);
					});
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep {
		.u-navbar--fixed {
			background: linear-gradient(to bottom, #B9DDFF, #D7EAF3);
		}
	}

	.head {
		background: linear-gradient(to bottom, #B9DDFF, #D7EAF3);
	}

	.top_box {
		background-color: white;
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		box-sizing: border-box;
		padding: 20rpx 20rpx 0 20rpx;
	}

	.search_box {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.search {
		width: 92%;
	}

	.list_box {
		box-sizing: border-box;
		padding: 20rpx;
	}

	.list_info {
		box-sizing: border-box;
		padding: 20rpx;
		background-color: white;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
	}

	.l_img {
		width: 140rpx;
		height: 140rpx;
		border-radius: 20rpx;
		vertical-align: bottom;
		margin-right: 10rpx;
	}

	.flex {
		display: flex;
	}

	.flexc {
		display: flex;
		align-items: center;
	}

	.sku {
		font-size: 24rpx;
		color: #C1C1C1;
		margin-top: 20rpx;
		align-items: center;
	}

	.xian {
		width: 3rpx;
		height: 30rpx;
		background-color: #C1C1C1;
		margin: 0 20rpx;
	}

	.num_box {
		font-size: 26rpx;
		color: #C1C1C1;
		display: flex;
		align-items: center;
		flex-wrap: wrap;

	}

	.mt {
		margin-top: 20rpx;
		width: 33.33%;
	}

	.num {
		font-size: 28rpx;
		color: black;
		margin-left: 10rpx;
	}

	.bitmap {
		text-align: center;
		padding-top: 100rpx;
	}

	.bitmap image {
		width: 60%;
	}

	.bitmap view {
		color: gray;
		font-size: 26rpx;
		margin-top: 30rpx;
	}

	.bot_box {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		background-color: white;
		box-sizing: border-box;
		padding: 20rpx 0 45rpx 0;
	}

	.btn {
		width: 80%;
		text-align: center;
		margin: 0 auto;
		color: white;
		background-color: #13AE67;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 25rpx;
	}

	.status {
		margin-left: auto;
		font-size: 26rpx;
	}
</style>